package com.zhongke.common.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieAnimationView;
import com.zhongke.common.R;

/**
 * Author: wpt
 * Time: 2021/11/26
 *
 * @Desc：loading ImageView直接引用anim文件方式
 */
public class ZKLoadingView extends FrameLayout {

    private LottieAnimationView lottieAnimationView;

    public ZKLoadingView(@NonNull Context context) {
        this(context, null);
    }

    public ZKLoadingView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public ZKLoadingView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, -1);
    }

    public ZKLoadingView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.base_include_loading_new, this);
        lottieAnimationView = findViewById(R.id.lottieLoading);
    }

    public void show() {
        setVisibility(View.VISIBLE);
        lottieAnimationView.playAnimation();
    }

    public void show(String title) {
        show();
    }

    public void dismiss() {
        lottieAnimationView.cancelAnimation();
        setVisibility(View.GONE);
    }
}
